/* This is a simple demonstration program for CircBuf */

/* This program puts the numbers 0, 1 and 2 on a FIFO and reads them back */

#include <stdio.h>

#include "circbuf.h"

int main(void)
{
	CircularBuffer* cb;
	euint8 buffer[40]; /* 10 places of size 4 */
	euint32 *d,c;

	/* Init */	
	cb = cb_create(buffer, 10, 4); 

	/* Put values */
	for(c=0;c<10;c++){
		d = (euint32*)cb_writePacket(cb); if(d==0)return(-1);
		*d=c;
		
		cb_printStatus(cb);
		cb_doneWritePacket(cb);
		printf("last packet is in ?  %s \n",cb_moreComing(cb) ? "No" : "Yes" );
	}
	cb_lastPacketIsIn(cb);
	printf("last packet is in ?  %s \n",cb_moreComing(cb) ? "No" : "Yes" );

	cb_printStatus(cb);
	for(c=0;c<10;c++){
		d = (euint32*)cb_readPacket(cb); if(d==0)return(-1);
		printf("%d\n",*d);

		cb_printStatus(cb);
		cb_doneReadPacket(cb);
		printf("last packet is out? %s \n",cb_readyReading(cb) ? "Yes" : "No");
	}
	cb_lastPacketIsOut(cb);
	printf("last packet is out? %s \n",cb_readyReading(cb) ? "Yes" : "No");

	free(cb);
}
